<template>
    <div>
        <a-row type="flex" justify="space-between" class="mb-1 mr-p5">
            <a-space>
                <date-packer placeholder="开始日期" v-model="dataReq.create_time_start"/>
                <date-packer placeholder="结束日期" v-model="dataReq.create_time_end"/>
<!--                ant bug v-model 无效-->
                <a-select
                        style="width: 85px;"
                        @change="(value)=>dataReq.CandlestickInterval= value"
                        allowClear
                        placeholder="级别"
                >
                    <a-select-option value="15min">15min</a-select-option>
                    <a-select-option value="30min">30min</a-select-option>
                    <a-select-option value="60min">60min</a-select-option>
                </a-select>
                <loading-button msg="搜索" @confirm="getData"/>
            </a-space>
        </a-row>

        <a-table
                style="width: 600px;"
                bordered
                :loading="loading"
                :columns="columns"
                :data-source="tableData.list"
                :pagination="paginationConfig(tableData)"
                :scroll="{ y: 'calc(100vh - 245px)' }"
                rowKey="id"
                @change="getData">
        </a-table>
    </div>
</template>

<script>
    import paginationConfig from "@/assets/styles/ant";
    import {ethStatisticsProfit} from "@/assets/api/api";
    import DatePacker from "@/components/DatePacker";
    import LoadingButton from "@/components/LoadingButton";

    const columns = [
        {title: '日期', dataIndex: 'create_time', width: 150},
        {title: '级别', width: 100, dataIndex: 'period'},
        {title: '利润', dataIndex: 'profit', width: 100}
    ];

    const dataReq = {
        CandlestickInterval: undefined,
        create_time_start: null,
        create_time_end: null,
        pagerIndex: 1,
        pagerNum: 50,
    }

    export default {
        name: "StatisticsProfit",
        components: {LoadingButton, DatePacker},
        data() {
            return {
                columns,
                loading: false,
                dataReq,
                tableData: {},
                profit: 0
            }
        },
        methods: {
            paginationConfig,
            getData(p) {
                this.dataReq.pagerIndex = p ? p.current : 1;
                this.dataReq.pagerNum = p ? p.pageSize : this.dataReq.pagerNum;

                this.loading = true;
                this.$post(ethStatisticsProfit, this.dataReq).then(value => {
                    this.loading = false;
                    if (value.code === 200) {
                        this.tableData = value.data;
                    }
                });
            }
        },
        mounted() {
            this.getData();
        }
    }
</script>

<style scoped>

</style>